;(async function(){
    const express = require("express")
    const mongoose = require("mongoose")
    const model = require("./db/model")
    const db = require("./db/db")
    try{
        await db
        console.log("数据库连接成功")
        const app = express()
        app.use(express.urlencoded({extended:false}))
        app.get("/get",async (req,res)=>{
            const result = await model.find({name:"轩轩"},{name:1,age:1})
            res.send(result)
        })
        app.post("/submit",async (req,res)=>{
            try{
                const {name,age} = req.body
                await model.create({name,age})
                res.send("提交成功")
            }catch(err){
                res.send("提交失败")
            }
        })
        app.listen(5000,(err)=>{
            if(err) console.log("失败")
            else console.log("成功")
        })
    }catch(err){
        console.log("数据库连接失败")
    }
})()